//
//  UECaseCell.m
//  UEHtml-iOS
//
//  Created by ShadowKnight on 13-10-1.
//  Copyright (c) 2013年 Qun He. All rights reserved.
//

#import "UECaseCell.h"
#import "UIConstanstDefine.h"


#define CASECELL_FONTCOLOR_AUTHOR RGBCOLOR(94, 94, 94)


@implementation UECaseCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
//        self.selectionStyle= UITableViewCellSelectionStyleNone;
        
        //------Icon image initialized------//
        float iconPosY = 81.0f;
        
        self.caseVisitIcon = [[UIImageView alloc] initWithFrame:CGRectMake(164, iconPosY, CASECELL_WIDTH_OF_ICON, CASECELL_WIDTH_OF_ICON)];
        [self.caseVisitIcon setImage:IMAGE_BY_NAMED(@"case_accessed_normal.png")];
        [self.contentView addSubview:self.caseVisitIcon];
        
        self.caseCommentIcon = [[UIImageView alloc] initWithFrame:CGRectMake(164+CASECELL_DISTANCE_OF_ICON, iconPosY, CASECELL_WIDTH_OF_ICON, CASECELL_WIDTH_OF_ICON)];
        [self.caseCommentIcon setImage:IMAGE_BY_NAMED(@"case_comment_normal.png")];
        [self.contentView addSubview:self.caseCommentIcon];
        
        self.caseFavorateIcon = [[UIImageView alloc] initWithFrame:CGRectMake(164+2*CASECELL_DISTANCE_OF_ICON, iconPosY, CASECELL_WIDTH_OF_ICON, CASECELL_WIDTH_OF_ICON)];
        [self.caseFavorateIcon setImage:IMAGE_BY_NAMED(@"case_favorate_normal.png")];
        [self.contentView addSubview:self.caseFavorateIcon];
        
        //--------Multi count lable initialized-----//
        self.caseVisitCount = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.caseVisitIcon.frame)+2, CGRectGetMidY(self.caseVisitIcon.frame)-4, CASECELL_WIDTH_OF_COUNT_LABEL, 8)];
        [self.caseVisitCount setFont:[UIFont systemFontOfSize:8.0f]];
        [self.caseVisitCount setText:@"2012"];
        [self.caseVisitCount setTextColor:CASECELL_FONTCOLOR_COUNT_DESC];
        [self.caseVisitCount setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:self.caseVisitCount];
        
        self.caseCommentCount = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.caseCommentIcon.frame)+2, CGRectGetMidY(self.caseCommentIcon.frame)-4, CASECELL_WIDTH_OF_COUNT_LABEL, 8)];
        [self.caseCommentCount setFont:[UIFont systemFontOfSize:8.0f]];
        [self.caseCommentCount setText:@"2012"];
        [self.caseCommentCount setTextColor:CASECELL_FONTCOLOR_COUNT_DESC];
        [self.caseCommentCount setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:self.caseCommentCount];
        
        self.caseFavorateCount = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.caseFavorateIcon.frame)+2, CGRectGetMidY(self.caseFavorateIcon.frame)-4, CASECELL_WIDTH_OF_COUNT_LABEL, 8)];
        [self.caseFavorateCount setFont:[UIFont systemFontOfSize:8.0f]];
        [self.caseFavorateCount setText:@"2012"];
        [self.caseFavorateCount setTextColor:CASECELL_FONTCOLOR_COUNT_DESC];
        [self.caseFavorateCount setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:self.caseFavorateCount];
        
        //------Title & Author of case----//
        self.caseTitle = [[UILabel alloc] initWithFrame:CGRectMake(164, 20, 136, 14)];
        [self.caseTitle setFont:[UIFont systemFontOfSize:13.0f]];
//        [self.caseTitle setText:@"HE.QUN"];
        [self.caseTitle setTextColor:[UIColor blackColor]];
        [self.caseTitle setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:self.caseTitle];
        
        self.caseAuthor = [[UILabel alloc] initWithFrame:CGRectMake(164, CGRectGetMaxY(self.caseTitle.frame)+10, 136, 10)];
        [self.caseAuthor setFont:[UIFont systemFontOfSize:9.0f]];
//        [self.caseAuthor setText:@"by feiyue"];
        [self.caseAuthor setTextColor:HEXCOLOR(0x666666)];
        [self.caseAuthor setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:self.caseAuthor];
        
        UIImageView* cellSeparateLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, 121, 320, 1)];
        [cellSeparateLine setImage:IMAGE_BY_NAMED(@"case_cell_Line.png")];
        [self.contentView addSubview:cellSeparateLine];
        
        //---------Image fetched from URL initialized------//
        self.casePreview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 140, 101)];
        [self.contentView addSubview:self.casePreview];
        
        self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
        self.selectedBackgroundView.backgroundColor = HEXCOLOR(0xf4f4f4);
    }
    return self;
}

-(void)initWithCaseData:(NSString *)title author:(NSString *)author commentCount:(NSString *)commentCount visitCount:(NSString *)visitCount favorateCount:(NSString *)favorateCount
{
    self.caseTitle.text = title;
    self.caseAuthor.text = [NSString stringWithFormat:@"by %@", author];
    self.caseCommentCount.text = commentCount;
    self.caseVisitCount.text = visitCount;
    self.caseFavorateCount.text = favorateCount;
}

-(void)imageViewHasLoadedImage:(UIImageView *)imageView
{
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
